/**
 * 
 */
package hu.gbalage.owlforms.impl;

import org.semanticweb.owl.model.OWLCardinalityRestriction;
import org.semanticweb.owl.model.OWLDataExactCardinalityRestriction;
import org.semanticweb.owl.model.OWLDataMaxCardinalityRestriction;
import org.semanticweb.owl.model.OWLDataMinCardinalityRestriction;
import org.semanticweb.owl.model.OWLObjectExactCardinalityRestriction;
import org.semanticweb.owl.model.OWLObjectMaxCardinalityRestriction;
import org.semanticweb.owl.model.OWLObjectMinCardinalityRestriction;

import hu.gbalage.owlforms.api.FieldCardinality;

/**
 * @author Grill Balazs (balage.g@gmail.com)
 *
 */
public class FieldCardinalityFactory {

	public static FieldCardinality createFieldCardinality(OWLCardinalityRestriction<?,?> cardinality){
		if ((cardinality instanceof OWLDataExactCardinalityRestriction)||
			(cardinality instanceof OWLObjectExactCardinalityRestriction)){
			return new ExactFieldCardinality(cardinality.getCardinality());
		}
		if ((cardinality instanceof OWLDataMinCardinalityRestriction)||
			(cardinality instanceof OWLObjectMinCardinalityRestriction)){
			return new MinFieldCardinality(cardinality.getCardinality());
		}
		if ((cardinality instanceof OWLDataMaxCardinalityRestriction)||
			(cardinality instanceof OWLObjectMaxCardinalityRestriction)){
			return new MaxFieldCardinality(cardinality.getCardinality());
		}
		return null;
	}
	
	public static void setFieldCardinality(FieldImpl field,OWLCardinalityRestriction<?,?> cardinality){
		FieldCardinality car = createFieldCardinality(cardinality);
		if (field.getCardinality() != null)
			car = new AndFieldCardinality(field.getCardinality(),car);
		field.setCardinality(car);
	}
	
}
